package com.friend.chat.db

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import com.friend.chat.db.dao.MessageDao
import com.friend.chat.db.entity.MessageEntity

/**
 * @des
 * @author batie fancy
 * @date 2023/1/7
 */
@Database(entities = [MessageEntity::class], version = 1,exportSchema = false)
abstract class ChatDatabase : RoomDatabase(){
    abstract fun messageDao():MessageDao

    companion object {
        private var instance: ChatDatabase? = null
        @Synchronized
        fun getDatabase(context: Context): ChatDatabase {
            instance?.let {
                return it
            }
            return Room.databaseBuilder(context.applicationContext, ChatDatabase::class.java, "chat_database").build().apply {
                instance = this
            }
        }
    }
}